package com.example.aigc_education.ws.handler;

import com.example.aigc_education.rpc.api.v2.ChatServiceProto;

public abstract class AbstractMessageHandler implements MessageHandler {

    @Override
    public boolean canHandle(ChatServiceProto.ChatMessage chatMessage) {
        if (chatMessage.getContentsCount() == 0) return false;

        if (getRole() == ChatServiceProto.Role.THINKING_VALUE) {
            return chatMessage.getRole() == ChatServiceProto.Role.THINKING_VALUE;
        } else if (getRole() == ChatServiceProto.Role.AI_VALUE) {
            return chatMessage.getRole() == ChatServiceProto.Role.AI_VALUE &&
                    getType().equals(chatMessage.getContents(0).getType());
        }else if (getRole() == ChatServiceProto.Role.HUMAN_VALUE){
            return chatMessage.getRole() == ChatServiceProto.Role.HUMAN_VALUE &&
                    getType().equals(chatMessage.getContents(0).getType());
        }

        return false;
    }

    protected abstract int getRole();

    protected String getType() {
        return "";
    }
}
